package main

import (
	"context"
	"fmt"
	"net/http"
	"os"
	"os/signal"
	"strconv"
	"time"

	"github.com/gin-gonic/gin"
)

var (
	name      string
	version   string
	buildTime string
)

func init() {
	if name != "" {
		fmt.Printf("%-12s%s\n", "App:", name)
	}
	if version != "" {
		fmt.Printf("%-12s%s\n", "Version:", version)
	}
	if buildTime != "" {
		if ut, _ := strconv.ParseInt(buildTime, 10, 64); ut > 0 {
			fmt.Printf("%-12s%s\n", "BuildTime:", time.Unix(ut, 0).Format(time.RFC3339))
		}
	}
}

func main() {
	interrupt, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
	defer cancel()

	mux := gin.Default()
	handleRoutes(mux)
	handleStatus(mux)
	startWebServer(interrupt, &http.Server{Handler: mux})
}
